package com.ZengQi.event.controller;

import com.ZengQi.event.entity.User;
import com.ZengQi.event.service.UserService;
import com.ZengQi.event.service.impl.UserServiceImpl;
import com.ZengQi.event.util.UpdateUtils;
import com.ZengQi.event.view.LoginView;
import com.ZengQi.event.view.RegisView;

import javax.swing.*;

public class RegisController {
    private RegisView regisView;
    public RegisController(RegisView regisView){
        this.regisView=regisView;
    }
    //用户注册
    public void regis(User user){
        if (user.getLoginPnum() == null || "".equals(user.getLoginPnum().trim()) || user.getLoginPwd() == null || "".equals(user.getLoginPwd().trim())||user.getUserName()==null||"".equals(user.getUserName().trim())||user.getUserBirthday()==null||"".equals(user.getUserBirthday().trim())||user.getUserSex()==null||"".equals(user.getUserSex())) {

            JOptionPane.showMessageDialog(regisView,"各项数据不能为空！！");
            return;

        }

            UserService userService=new UserServiceImpl();
        boolean saveUser = userService.saveUser(user);
        if(saveUser) {
            JOptionPane.showMessageDialog(regisView,"注册成功！！！");

            new LoginView();
            regisView.dispose();
        }else{
            JOptionPane.showMessageDialog(regisView,"手机号或昵称重复！");

        }


    }
}
